<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta
      name="viewport"
      content="width=device-width,initial-scale=1.0,maximum-scale=1.0,user-scalable=0"
    />
    <meta name="msapplication-tap-highlight" content="no" />
    <meta http-equiv="X-UA-Compatible" content="ie=edge" />
    <meta http-equiv="Pragma" content="no-cache" />
    <meta http-equiv="Expires" content="0" />
    <meta http-equiv="Cache-control" content="no-cache,must-revalidate" />
    <meta http-equiv="Cache" content="no-cache" />
    <title>提交漏洞</title>
    <link rel="stylesheet" href="__STATIC__static/element-ui/element-ui@2.15.14.min.css" />
    <script>
      document.write(`<link rel="stylesheet" href="__STATIC__css/post-bug.css?v=${Date.now()}">`, )
      window.APP_PROJECT="modules/xsrc";window.GTXY_VERSION=1726277890818;window.APP_ENV="dev";
    </script> 
  </head>
<include file="Public/header" title="提交漏洞" banner_selected="nav_item-active"/> 
<script type="text/javascript" src="__PUBLIC__/ueditor/ueditor.config.js"></script>
<script type="text/javascript" src="__PUBLIC__/ueditor/ueditor.all.js"></script> 
<script src="__PUBLIC__/Static/ZeroClipboard.min.js"></script>
<script type="text/javascript">
    var ue = UE.getEditor('post-content',{
        toolbars: [
            ['simpleupload','link','unlink', '|', 'selectall', 'cleardoc'],
        ],
        initialFrameHeight:300,
        zIndex:100,
    }); 
    // 监听光标变化事件
    ue.addListener('selectionchange', function () {
        // 获取编辑器内容
        var content = ue.getContent();  
        console.log(content);
        // 将内容存入隐藏域
        document.getElementById('post-content').value = content;
    });

    // 可选：也可以监听 blur 事件
    ue.addListener('blur', function () {
        // 当编辑器失去焦点时，同样更新隐藏域
        var content = ue.getContent(); 
        console.log(content);
        document.getElementById('post-content').value = content;
    });
	/**恢复自动保存内容
　　setTimeout(function () {
        ue.execCommand('drafts');
    }, 500);  
	**/
</script>
  <body>
    <div id="app" :class="[isTop ? '' : 'scroll']" v-cloak> 
      <div class="app-body">
        <div class="body-section">
          <div class="title">提交漏洞</div>
          <div class="divider-line"></div>
          <div class="container" style="margin-top: 0px;">
            <el-form ref="postForm" :model="postForm" :rules="postRules" class="post-form" label-width="94px">
              <el-form-item class="form-item" label="漏洞名称：" prop="title">
                <el-input v-model="postForm.title" placeholder="请输入漏洞名称"></el-input>
              </el-form-item>
              <el-form-item class="form-item" label="漏洞类型：" prop="cate_id2">
                <div class="item-col-2">
                  <el-select v-model="postForm.cate_id" placeholder="请选择漏洞类型" @change="changeCat1">
                    <el-option v-for="item in cat1Options" :key="item.id" :label="item.name" :value="item.id" :disabled="item.disabled"></el-option>
                  </el-select>
                  <el-select v-model="postForm.cate_id2" placeholder="请选择漏洞类型">
                    <el-option v-for="item in cat2Options" :key="item.id" :label="item.name" :value="item.id" :disabled="item.disabled"></el-option>
                  </el-select>
                </div>
              </el-form-item>
              <el-form-item class="form-item" label="漏洞类型：" prop="level_id">
                <el-select v-model="postForm.level_id" placeholder="请选择漏洞等级" style="width: 100%;">
                  <el-option v-for="item in levelOptions" :key="item.value" :label="item.label" :value="item.value"></el-option>
                </el-select>
              </el-form-item> 
               <el-form-item class="form-item" label="漏洞描述：" prop="property"> 
              <div class="mod-form-block mod-form-block-textarea mod-form-block-textarea-description"> 
                  <div>
                      <div>
                          <script  v-model="postForm.content" id="post-content" name="content" type="text/plain" style="width:100%"></script>
                      </div>
                      <span class="formtips-error">您输入的漏洞描述有误，请重新输入</span>
                  </div>
              </div> 
              </el-form-item> 
               <el-input v-model="postForm.content"  placeholder="请输漏洞描述" style="display:none;"></el-input> 
              <el-form-item class="form-item" label="影响资产：" prop="property">
                <el-input v-model="postForm.property" type="textarea" placeholder="请输入受影响资产，输入域名或者IP即可，无需https://和端口等信息" :rows="4"></el-input>
              </el-form-item>
              <el-form-item class="form-item" label="上传附件：" prop="file">
                <div class="item-col-2">
                  <el-upload
                    ref="upload"
                    action="__ROOT__/user.php?m=user&c=post&a=attachment_upload"
                    :headers="uploadHeader"
                    :limit="1"
                    :show-file-list="false"
                    :before-upload="beforeUpload"
                    :on-success="uploadSuccess"
                    :on-remove="removeFile"
                  >
                    <el-button type="primary" class="select-btn">选择文件</el-button>
                  </el-upload>
                  <div class="form-tip">格式限制：7z、zip、pdf，请上传小于8M的文件</div>
                </div>
                <el-alert v-if="uploadOptions.status === 1" type="success" :closable="false" title="上传成功，可继续进行提交"></el-alert>
                <el-alert v-if="uploadOptions.status === -1" type="error" :closable="false" title="上传失败，请检查文件格式和大小"></el-alert>
              </el-form-item>
              <el-form-item class="form-item" label="验证码：" prop="verify">
                <div class="item-col-2">
                  <el-input v-model="postForm.verify" autocomplete="off" id="J_code"  placeholder="验证码"></el-input>
                  <div class="img-code-box">
                    <img :src="verifyUrl" alt="" class="image-code" @click="getCode" />
                    <div class="reset-btn" @click="getCode">换一张</div>
                  </div>
                </div>
              </el-form-item>
              <el-form-item class="form-item">
                <div class="form-danger-tip">在漏洞修复之前，请不要向外界传播</div>
                <el-button class="submit-btn" @click="submit">提交漏洞</el-button>
              </el-form-item>
            </el-form>
            <div class="warm-tips">
              <div class="warm-tips-title">温馨提示：</div>
              <div class="warm-tips-content">
                <p class="content-title">我们关注的内容</p>
                <p class="content-block">Web服务漏洞</p>
                <p class="content-block">PC客户端软件漏洞</p>
                <p class="content-block">手机客户端软件漏洞</p>
                <p class="content-block">威胁情报</p>
                <p class="content-title">我们的评判标准</p>
                <p class="content-block">标准详情请查看<a href="/index.php?m=&c=page&a=view&id=1">《GSRC漏洞处理和评分标准》</a></p>
              </div>
            </div>
          </div>
        </div>

      </div>
    </div>
  </body>
  <script src="__STATIC__jquery.min.js"></script> 
  <script src="__STATIC__js/layer/layer.js"></script> 
  <script src="__STATIC__static/vue/vue@2.6.14.min.js"></script>
  <script src="__STATIC__static/element-ui/element-ui@2.15.14.min.js"></script>
  <script src="__STATIC__static/require/require@2.3.6.min.js"></script>
  <script> 
    require.config({
      urlArgs: `v=${Date.now()}`,
      paths: {
        axios: '__STATIC__static/axios/axios@1.2.0.min',
        CryptoJS: '__STATIC__static/crypto-js/crypto-js@4.1.1.min',
        common: '__STATIC__js/base/common',
        util: '__STATIC__js/base/util',
        api: '__STATIC__js/base/api',
        request: '__STATIC__js/base/request',
        storage: '__STATIC__js/base/storage',
      }
    });
    require(['common', 'util', 'storage', 'api','request'], function (common, util, storage, api, request) {
      new Vue({
        el: '#app',
        data() {
          return {
            loading: false,
            isTop: true,  
            postForm: {
              title: '',
              cate_id: '',
              cate_id2: '',
              level_id: '',
              content: '',
              property: '',
              file: '',
              verify: '', 
            },
            postRules: {
              title: [{ required: true, trigger: 'blur', message: '请输入漏洞名称' }],
              cate_id2: [{ required: true, trigger: 'blur', message: '请选择漏洞类型' }],
              level_id: [{ required: true, trigger: 'blur', message: '请选择漏洞等级' }],
              //content: [{ required: true, trigger: 'blur', message: '请填写漏洞描述' }],
              property: [{ required: true, trigger: 'blur', message: '请填写影响资产' }],
              verify: [{ required: true, trigger: 'blur', message: '请输入验证码' }],
            },
            typeList: [
              {
                id: '1',
                name: 'WEB漏洞',
                children: [
                  { id: '11', name: 'XSS漏洞' },
                  { id: '12', name: '命令注入' },
                  { id: '13', name: 'SQL注入' },
                ],
              },
              {
                id: '2',
                name: '移动端漏洞',
                children: [
                  { id: '21', name: '信息泄漏' },
                  { id: '22', name: '逻辑漏洞' },
                  { id: '23', name: 'SQL注入' },
                ],
              },
            ],
            levelOptions: [
              { label: '严重', value: '5' },
              { label: '高危', value: '4' },
              { label: '中危', value: '3' },
              { label: '低危', value: '2' },
            ],
            uploadOptions: {
              accept: ['7z', 'zip', 'pdf'],
              maxSize: 8 * 1024 * 1024,
              status: 0, // 0 待上传 1成功 -1失败
            },
            verifyUrl: '',
          };
        },
        computed: {
          cat1Options() {
            const res = [...this.typeList];
            if (res.length > 0) {
              return res;
            }
            return [
              { id: '', name: '请选择漏洞类型', disabled: true },
            ];
          },
          cat2Options() {
            const cat1 = this.postForm.cate_id;
            const row = this.typeList.find(item => item.id === cat1);
            if (row) {
              const res = [...row.children];
              if (res.length > 0) {
                return res;
              }
            }
            return [
              { id: '', name: '请选择漏洞类型', disabled: true },
            ];
          },
          uploadHeader() {
            return { 
            };
          }
        }, 
        watch: {},
        created() {
          this.onScroll();
          this.getCode(); 
          this.fetchData();
        }, 
        methods: {
          onScroll() {
            util.onScroll([
              { ele: document, type: 'top', fn: () => {
                  this.isTop = true;
                  // 滚动非顶部解禁
                  return { 70: false };
                }},
              { ele: document, type: 70, fn: () => {
                  this.isTop = false;
                  // 滚动非顶部禁用
                  return { 70: true };
                }},
            ]);
          },
          fetchData() {
        	  request.post("__ROOT__/user.php?m=user&c=post&a=ajaxSubCategory", this.postForm).then((res) => {
        		  this.typeList = res; // 更新 typeList
        	  });
          },
          changeCat1() {
            this.postForm.cate_id2 = '';
          },
          beforeUpload(file) {
            const { accept, maxSize } = this.uploadOptions;
            const [_, ext] = file.name.split('.'); 
            if (accept.includes(ext) && maxSize >= file.size) { 
              return file;
            } else {
              this.uploadOptions.status = -1;
              this.$message.error('请上传小于8M的，格式为7z/zip/pdf的文件');
              return false;
            }
          },
          uploadSuccess(res, file, fileList) {
            if (res.code == 200) { 
              this.postForm.file = res.savepath;
              this.uploadOptions.status = 1;
            } else {
              this.uploadOptions.status = -1;
            } 
            this.$refs.upload.clearFiles();
          },
          removeFile() {
            this.postForm.file = '';
          },
          getCode() {
            // TODO 获取图片验证码 及 uuid
            // this.verifyUrl = "data:image/gif;base64," + res.img;
            // this.postForm.uuid = res.uuid; 
              // TODO 获取图片验证码 及 uuid 
              this.verifyUrl = "{:U('login/verify')}&tab=post&key=" + new Date().getTime();  
          },
          submit() {
            this.$refs.postForm.validate((valid, obj) => {
            	 var content = ue.getContent(); 
            	 this.postForm.content = content;
              console.log(valid, obj);
              if(valid == true){
	              var content = ue.getContent(); // 获取编辑器内容
	              console.log(content);
	              request.post("{:U('Post/add')}", this.postForm).then((res) => {
	                  console.log('res', res) 
	                  if(res.code == 200){
	                	  layer.msg(res.msg,{icon:1,time:2000,
					    		end:function(){
					    			window.location.href =res.url;
				    			}
						    });  
	                  }else{
	                	  layer.msg(res.msg,{icon:2,time:2000, end:function(){  
		  						var url = "{:U('login/verify')}&tab=post&key=" + new Date().getTime();  
		  						$(".image-code").attr("src", url); 
		  						$("#J_code").val(""); 
		  						}
	                    	});
	                  }
	                }).catch((err) => {
	                  console.log('err', err)
	                });
	                this.loading = false;  
              }
            });
          }
        }
      });
    });
  </script>
</html>
